// pages/tabar/tabar.js
Page({
    
}),
Component({
    // 组件的属性列表
    properties: {
      // 接受父组件的给的数据
      active: {
          type: "String",
          value: ""
      }
    },
    data: { 
      selected: undefined,
      color: "#33a3dc",  //默认文字颜色
      selectedColor: "#e6a511",  //选中文字颜色
      list: [
        {
            "pagePath": "pages/index/index",
            "text": "首页",
            "iconPath": "/images/首页.png",
            "selectedIconPath": "/images/首页 (1).png"
        },
        {
            "pagePath": "pages/desktop/sort/sort",
            "text": "分类",
            "iconPath": "/images/分类.png",
            "selectedIconPath": "/images/分类 (1).png"
        },
        {
            "pagePath": "pages/ShoppingCart/ShoppingCart",
            "text": "购物车",
            "iconPath": "/images/购物车.png",
            "selectedIconPath": "/images/购物车 (1).png"
        },
        {
            "pagePath": "pages/admin/admin",
            "text": "我的",
            "iconPath": "/images/代理商-1.png",
            "selectedIconPath": "/images/代理商-1 (1).png"
        }
    ]
    },
    attached() {
      
    },
    methods: {
      switchTab(e) {
        if (this.data.selected === e.currentTarget.dataset.index) {
          return false;
        } else {
          const url=e.currentTarget.dataset.path
          wx.switchTab({url})
        }
      },
      run() {
        console.log(this.data.active);      
        this.setData({
            // 通过this.data获取父组件里传过来的值
            selected: this.data.active
        });
        console.log(this.data.selected);
      }
    },
    onShow: function () {
        if (typeof this.getTabBar === 'function' &&
        this.getTabBar()) {
        this.getTabBar().setData({
          selected: null  //标亮的导航按钮的下标，如果是其他子页面，可以赋值为null
        })
      }
     },
  })